//
//  FFNavigationController.m
//  FFUIKit
//
//  Created by NoNo on 15/11/3.
//  Copyright © 2015年 nono. All rights reserved.
//

#import "FFNavigationController.h"
#import "FFDefine.h"
#import "UIBarButtonItem+FFExpansion.h"

@interface FFNavigationController ()<UINavigationControllerDelegate,UIGestureRecognizerDelegate>

@end

@implementation FFNavigationController

+ (void)initialize
{
    // 设置整个项目所有item的主题样式
    UIBarButtonItem *item = [UIBarButtonItem appearance];
    
    // 设置普通状态
    // key：NS****AttributeName
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:15];
    [item setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    
    // 设置不可用状态
    NSMutableDictionary *disableTextAttrs = [NSMutableDictionary dictionary];
    disableTextAttrs[NSForegroundColorAttributeName] = [UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:0.7];
    disableTextAttrs[NSFontAttributeName] = textAttrs[NSFontAttributeName];
    [item setTitleTextAttributes:disableTextAttrs forState:UIControlStateDisabled];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationBar.barTintColor = [UIColor colorWithHexString:@"2ab2ff"];
}

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    
//    NSLog(@"%ld",self.viewControllers.count);
    //    NSLog(@"push\n%@",NSStringFromClass([viewController class]));
    if (self.viewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
        // 设置左边的返回按钮
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(back) image:@"nav_leftaArrows" highImage:@"nav_leftaArrows"];
    }else{
        viewController.hidesBottomBarWhenPushed = NO;
    }
    [super pushViewController:viewController animated:YES];
    
}

+ (void)setNavTitleView:(NSString *)title childVc:(UIViewController *)childVc
{
    NSMutableDictionary *navTitleAttrs = [NSMutableDictionary dictionary];
    navTitleAttrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
    navTitleAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:20];
    
    NSMutableAttributedString *navAttrTitle = [[NSMutableAttributedString alloc]initWithString:title attributes:navTitleAttrs];
    
    CGPoint centerPoint = CGPointMake(FFScreenWidth * 0.5, FFScreenHeight * 0.5);
    
    UILabel *navTitleLabel = [[UILabel alloc]init];
    navTitleLabel.attributedText = navAttrTitle;
    
    navTitleLabel.textAlignment = NSTextAlignmentCenter;
    
    CGSize navTitleSize = [navTitleLabel sizeThatFits:CGSizeMake(100, 65)];
    
    UIView *navTitleView = [[UIView alloc]init];
    navTitleView.center = centerPoint;
    navTitleView.bounds = CGRectMake(0, 0, navTitleSize.width, navTitleSize.height);
    [navTitleView addSubview:navTitleLabel];
    navTitleLabel.frame = navTitleView.bounds;
//    UIView *bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, navTitleView.frame.size.height, navTitleView.frame.size.width, 1)];
//    bottomView.backgroundColor = [UIColor whiteColor];
//    [navTitleView addSubview:bottomView];
    
    childVc.navigationItem.titleView = navTitleView;
}

- (void)back
{
    [self popViewControllerAnimated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
